/**
 * 
 */
package info.niwota.profile.contact;

import java.io.Serializable;

/**
 * @author qiangli
 *
 */
public class EmailAddress implements Serializable {
	private static final long serialVersionUID = 1L;

	public String name;
	public String address;
	
	public EmailAddress() {
	}

	public EmailAddress(String address) {
		this.address = address;
	}

	public EmailAddress(String address, String name) {
		this.address = address;
		this.name = name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		return result;
	}

	/**
	 * @return true if email addresses are equal disregarding names
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		EmailAddress other = (EmailAddress) obj;
		if (address == null) {
			if (other.address != null) {
				return false;
			}
		} else if (!address.equals(other.address)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return (name == null ? address : name) +" <" + address + ">";
	}
}
